package com.ews.onlineexchange.controller;

import java.util.ArrayList;
import java.util.List;

import javax.enterprise.inject.Model;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import com.ews.onlineexchange.model.Bulletin;
import com.ews.onlineexchange.model.ChooseType;
import com.ews.onlineexchange.model.DataEntity;
import com.ews.onlineexchange.service.EntityQuery;

@Model
public class InChoosingAverageBulletinList extends EntityQuery<Bulletin> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	public InChoosingAverageBulletinList() {
		setMaxResults(MAX_RESULTS_NORMAL);
	}
	
	@Override
	protected List<Predicate> getRestrictions(CriteriaBuilder cb, Root<Bulletin> entity) {
		List<Predicate> restrictions = new ArrayList<>();
		restrictions.add(cb.equal(entity.get("delFlag"), DataEntity.DEL_FLAG_NORMAL));
		
		restrictions.add(cb.isFalse(entity.<Boolean>get("over")));		
		
		//过滤已经取消的公告
		restrictions.add(cb.isFalse(entity.<Boolean>get("cancelled")));
		
		restrictions.add( cb.equal( entity.get( "wayOfChoose" ), ChooseType.Average ) );
		
		return restrictions;
	}
}
